package com.siae.controller;


import com.siae.pojo.User;
import com.siae.pojo.vo.Result;
import com.siae.service.UserService;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/user")
@Tag(name = "UserController",description = "用户操作")
public class UserController {
    @Autowired
    private UserService userService;
    @GetMapping
    public Result<List<User>> findAllUser(@RequestParam(name = "roleId",defaultValue = "0") Integer roleId){
        return userService.findAllUser(roleId);
    }
    @GetMapping("/{id}")
    public Result<User> getUserById(@PathVariable("id") Integer id){
        return userService.getUserById(id);
    }

    /**
     * 新建用户 | 创建用户账号
     * */
    @PostMapping()
    public Result add(@RequestBody User user){
        return userService.addUser(user);
    }

    /**
     * 修改用户信息 | 逻辑删除信息
     *
     * */
    @PutMapping()
    public Result update(@RequestBody User user){
        return userService.updateUser(user);
    }
    @PutMapping("/pwd")
    public Result updatePwd(@RequestBody Map dataMap){
        return userService.updatePwd(dataMap);
    }

    /**
     * 彻底删除用户信息
     * */

    @DeleteMapping("/{id}")
    public Result deleteById(@PathVariable("id") Integer id){
        return userService.deleteUserById(id);
    }

}
